package org.lex.depends.core.analyzer;

import java.io.File;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;

import org.lex.io.utils.FileComparator;
import org.lex.lang.SystemUtils;

public class AnalyzerResult implements IAnalyzerResult {

	private Set<String> dependentClasses = new TreeSet<String>();
	private Set<String> unresolvedClasses = new TreeSet<String>();
	private Set<File> dependentFiles = new HashSet<File>();

	@Override
	public Collection<String> getDependentClasses() {
		return dependentClasses;
	}

	public void addDependentClass(String className) {
		this.dependentClasses.add(className);
	}

	@Override
	public Collection<File> getDependentFiles() {
		return dependentFiles;
	}

	public void addDependentFile(File file) {
		this.dependentFiles.add(file);
	}

	@Override
	public Collection<String> getUnresolvedClasses() {
		return unresolvedClasses;
	}

	public void addUnresolvedClass(String className) {
		this.unresolvedClasses.add(className);
	}

	public void clear() {
		this.dependentClasses.clear();
		this.dependentFiles.clear();
		this.unresolvedClasses.clear();
	}

	public String toString() {
		String nl = SystemUtils.getLineSeparator();

		StringBuilder buf = new StringBuilder();
		buf.append("Analyzer result is:").append(nl);
		buf.append("--dependent  classes size=").append(dependentClasses.size()).append(nl);
		for (String dc : dependentClasses) {
			buf.append("  ").append(dc).append(nl);
		}
		buf.append("--unresolved classes size=").append(unresolvedClasses.size()).append(nl);
		for (String uc : unresolvedClasses) {
			buf.append("  ").append(uc).append(nl);
		}
		buf.append("--dependent  files   size=").append(dependentFiles.size()).append(nl);
		File[] files = dependentFiles.toArray(new File[dependentFiles.size()]);
		Arrays.sort(files, FileComparator.INSTANCE);
		for (File f : files) {
			buf.append("  ").append(f).append(nl);
		}
		return buf.toString();
	}
}
